package com.itheima;

import com.itheima.common.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @author YangJiaHao
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(TokenException.class)
    public CommonResult tokenHandler() {
        return CommonResult.error("token失效");
    }

    // @ExceptionHandler(RuntimeException.class)
    // @ResponseBody
    // public CommonResult getRuntimeException(RuntimeException e) {
    //     log.info("全局异常捕获生效了");
    //     log.error(e.getMessage());
    //     return CommonResult.success("运行时异常");
    // }

    // @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    // public CommonResult usernameHandler(){
    //     return CommonResult.error("用户名已存在");
    // }
}
